package com.gears_software.bbnetwork.activitys;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.WindowFeature;
import org.androidannotations.annotations.sharedpreferences.Pref;

import android.app.Activity;
import android.content.Intent;
import android.view.Window;

import com.gears_software.bbnetwork.R;
import com.gears_software.bbnetwork.datas.finders.IBBNetworkFinder;
import com.gears_software.bbnetwork.datas.finders.impl.IBBNetworkFinderImpl;
import com.gears_software.bbnetwork.datas.models.ResultModel;
import com.gears_software.bbnetwork.datas.models.ReturnCode;
import com.gears_software.bbnetwork.utlis.BBNetworkSharedPref_;
import com.gears_software.bbnetwork.utlis.ToastUI;
import com.gears_software.common.utils.versionupdate.VersionModel;
import com.gears_software.common.utils.versionupdate.VersionUpdate;
/**
 * 闪屏页
 * @author DY-PC
 *
 */
@EActivity(R.layout.activity_blink)
@WindowFeature(Window.FEATURE_NO_TITLE)
public class BlinkActivity extends Activity {
	
	@Pref
	BBNetworkSharedPref_ sp;
	//版本更新类
	VersionUpdate versionUpdate;
	
	@Bean(IBBNetworkFinderImpl.class)
	IBBNetworkFinder finder;
	
	@Bean
	ToastUI toast;
	
	@AfterViews
	void onCreate(){
//		go();
		getModel();
	}
	
	@Background
	void getModel(){
		ResultModel<VersionModel> res = finder.getVersion();
		if(res.getReturnCode().equals(ReturnCode.SUCCEED)){
			init(res.getResObj());
		}else{
			showTxt("获取版本信息失败！"+res.getMessage());
		}
	}
	
	@UiThread
	void init(VersionModel model){
		versionUpdate = new VersionUpdate(this);
		boolean isversion = versionUpdate.versionUpdate(model, "BBNetwork", "", false,true);
		if(!isversion){
			go();
		}
	}
	
	@UiThread
	void showTxt(String txt){
		toast.ShowToast(txt);
	}
	
	@Background(delay = 2000)
	void go(){
		if(sp.cound().get().equals("1")){
			Intent intent = new Intent(this,GuideActivity_.class);
			startActivity(intent);
		}else{
			Intent intent = new Intent(this,LoginActivity_.class);
			startActivity(intent);
		}
		finish();
	}
}
